package com.kaisa.activity.adapter;

import android.content.Context;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaisa.activity.R;
import com.kaisa.activity.bean.Snap;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

/**
 * Created by 123 on 2015/12/17.
 */
public class SnapAdapter extends AppBaseAdapter<Snap> {
    public SnapAdapter(List<Snap> list, Context context) {
        super(list, context);
        inflater = LayoutInflater.from(context);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        SnapViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.snap_item, null);
            holder = new SnapViewHolder(convertView);
        } else {
            holder = (SnapViewHolder) convertView.getTag();
        }
        x.image().bind(holder.imageView, list.get(position).getPic());
        holder.titleTextView.setText(list.get(position).getName());
        holder.flagTextView.setText("北京出发");
        holder.dataTextView.setText("出发日期：" + list.get(position).getDate());
        holder.moneyTextView.setText("¥" + list.get(position).getNowprice());
        holder.oldTextView.setText("¥" + list.get(position).getPrice());
        return convertView;
    }

    public static class SnapViewHolder extends BaseViewHolder {
        @ViewInject(R.id.item_snap_img)
        private ImageView imageView;
        @ViewInject(R.id.item_snap_title)
        private TextView titleTextView;
        @ViewInject(R.id.item_snap_flag)
        private TextView flagTextView;
        @ViewInject(R.id.item_snap_money)
        private TextView moneyTextView;
        @ViewInject(R.id.item_snap_data)
        private TextView dataTextView;
        @ViewInject(R.id.item_snap_oldmoney)
        private TextView oldTextView;

        public SnapViewHolder(View convertView) {
            super(convertView);
            x.view().inject(this, convertView);
        }
    }
}
